home *** CD-ROM | disk | FTP | other *** search
/ Channel Z 6 / Channel Z - The A1200 Disk Magazine - Issue 6 (1994-06)(Channel Z)(AGA)(Disk 1 of 2).adf / Blitz / Blitz
Text File  |  1992-12-21  |  12KB  |  381 lines

  1.  
  2.  
  3.             B L I T Z  B A S I C  -  T U T O R I A L  # 1
  4.  
  5.  
  6.  
  7.  
  8. INTRODUCTION
  9.  
  10. Welcome to my first tutorial for Blitz Basic II. 
  11. In the coming tutorials I will be dealing with different aspects of a powerful
  12. language called Blitz Basic II, but before I go into that let me first 
  13. introduce myself.
  14.  
  15. My name is Rudy van Etten I live in the south of Holland in a little town 
  16. called Steenbergen. I have owned a  A500 for about 4 years now and have 
  17. recently bought a A1200. (like a lot of you lately)
  18. When I first hooked it up I immediately noticed the speed difference, I had
  19. placed my old A500 next to my A1200 so I could compare the speed, and I was
  20. quite pleased.
  21.  
  22. Knowing this and also knowing about the new graphic capabilities I was
  23. planning to go back to programming the amiga again. I used to program in Amos
  24. but I never released anything mainly because of a few reasons.
  25. First of all the executable files are to bloody big and you must state in your
  26. program that it was programmed in Amos, well that is like having lame written
  27. on your forehead.
  28. thirdly the speed was not a real plus point, however on A 1200 it is ofcourse
  29. faster.
  30. And last because Amos has been given the lame status, witch is to bad since it
  31. is pretty capable of standing up between the competition.
  32.  
  33. When I first heard of Blitz Basic, I thought, "hey, more speed more power I
  34. must get that language".
  35. So after weeks of calling stores all over Holland finally one store had the
  36. brains to include Blitz Basic in their software collection. So after a quick
  37. phone call and a day or two of camping out under the mailbox I was the proud
  38. owner of Blitz Basic II, only to discover that the manual isn't the least
  39. beginner friendly. (here's some old news!!)
  40.  
  41. I started to read,learn and experiment and I got more used with the command
  42. set every day.
  43.  
  44. That was one month ago and sins then I have produced, a few simple hardDisk
  45. menus for a quick selection of programs, a simple game experiment (a hi-tech
  46. flying dinosaur robot with the ability to land, coooool!, not!!), and a dorky
  47. looking menu for pack disks.
  48.  
  49. I hope in this tutorial that you will learn something new, and can begin your
  50. career as a famous, PD or Commercial programmer.
  51.  
  52.  
  53.  
  54. THE REAL START
  55.  
  56. Well how do you get started with Blitz Basic ?, usually you start with the
  57. installing of the software, but I hope you have done this for yourselves, it
  58. isn't so hard to do.
  59. After the installing you would probably start to look at the included PD
  60. Disks, I really liked the Star Trek game and the shoot 'em up game Cafeine
  61. Free, it really shows the power of Blitz Basic.
  62. Oh, before I forget, be sure that you send in the registration card, because
  63. if you do not register then you will not get any future updates.
  64.  
  65. After looking at the PD disks I started to look at the examples, not really
  66. something you can use, but they are Ok. After seeing and not understanding
  67. how they all really worked I started typing in little programs like NPrint
  68. "Hello" and Let a=10 : NPrint a, but after a few days the programs got bigger
  69. and better. Also what I liked is that the compiled version of your programs
  70. can be smaller than a few hundred bytes, unlike it's bronze aged cousin Amos.
  71.  
  72. What I really liked is that Blitz is also fully Assembler friendly, this
  73. meaning you can type any of the assembler mnemonics and Blitz will accept 
  74. them. 
  75. The Assembler section of Blitz will not be of use to many of you but
  76. it will be for the more experienced users amongst us.(I know your out there!)
  77. For myself however it is not of many use. (But I wish it was!)
  78.  
  79. However when I tried the assembler commands RTS, JSR and JMP I noticed that
  80. they have the same effect as Return, Gosub and Goto. 
  81.  
  82. Nowing the assembler Mnemonics I knew that RTS means return from subroutine
  83. and JSR means jump to subroutine and that JMP means jump to, so I tried em 
  84. out in a little program.
  85.  
  86. Nprint "One"  
  87.  
  88. JSR two                      ; same as gosub two
  89.  
  90. JMP three                    ; same as goto three
  91.  
  92. two:
  93. NPrint "Two"
  94. RTS                          ; same as return
  95.  
  96. three:
  97. NPrint "Three"
  98. MouseWait
  99. end
  100.  
  101. When I tried it I found out you can replace the gosubs goto's ect. with the
  102. mnemonics without causing problems.
  103.  
  104. But enough of that, I will go into that another time.
  105.  
  106. Wel, let me tell you how not to begin to start programming. Do not
  107. immediately start to memorize all the commands and think you know it all, I
  108. tried that with Assembler once and it didn't help a bit, I knew all
  109. mnemonics and knew not how to use them.
  110. The best is to start to make little programs and expand them when you learn
  111. a new command. Or Just the other way around, learn a new command and make a
  112. little program around it.
  113. Also the best is to look and study the examples in the books and on the disks
  114. and see how a single command works and how everything is set up.
  115.  
  116. If you have build up enough experience, then you can begin to program small
  117. routines, like controlling a shape via joystick or making a small intro ect.
  118. Later on you will get better and you can start to make bigger programs.
  119.  
  120.  
  121.  
  122. U S E R  I N P U T  T E S T . . 
  123.  
  124. Now I will show you a simple little program with just asks for your name and
  125. will print it.
  126.  
  127.  
  128. ;
  129. ; User input test..
  130. ;
  131.  
  132. WbToScreen 0                        ; Use the workbench screen
  133.  
  134. Print "What is your name : "            ; Print the string to the window
  135.  
  136. a$=Edit$(20)                        ; Input 20 characters
  137.  
  138.   NPrint "Hey ",a$," drop dead!!"       ; Print the result on the screen
  139.  
  140. For i=1 To 3                        ; Start three loops 
  141.   BeepScreen 0 : VWait 10               ; Beep the screen, wait a moment
  142. Next                                ; Next loop
  143.  
  144. VWait 60 : End                      ; Wait a sec., end of program
  145.  
  146.  
  147.  
  148.  
  149. Well I hope everybody sees how it all works and if you don't just look at the
  150. explanation of the commands below.
  151.  
  152.  
  153.  
  154. Statement : WbToScreen screen#
  155.  
  156.     WbToScreen Lets the workbench screen become your screen to work
  157.     with.
  158.  
  159.  
  160.  
  161. Statement : Print Expression
  162.  
  163.     Used to print text or numbers to the screen. Most Basic programmers
  164.     will recognize this one.
  165.  
  166.  
  167.  
  168. Statement : NPint Expression
  169.  
  170.     Same as Print but will move the cursor down one line after printing
  171.     the text or the numbers. 
  172.     
  173.     Also if you use the comma's then you can print extra variables and
  174.     strings like shown in the example.
  175.  
  176.  
  177.  
  178. Statement : Edit$(number_of_characters)
  179.  
  180.     Edit$ string is what Input$ was for Amos, only it's more powerful
  181.     You can set the number of characters to be read in, so if there is
  182.     more input from the user, it will not be printed on the screen or
  183.     placed in the string.
  184.  
  185.  
  186.  
  187. Statement : For Var=Expression1 To Expression2
  188.  
  189.     For is used to start a loop for a number of times, see the example.
  190.  
  191.  
  192.  
  193. Statement : Next [Var[Var..]
  194.  
  195.     Used to end a For/Next loop, after this command is given then the
  196.     program will either jump back for another loop or end the loop and
  197.     go on with the program.
  198.  
  199.  
  200.  
  201. Statement : VWait [Frames]
  202.  
  203.     VWait on it own is used to wait until a the display is redrawn, this
  204.     is about 1/50 of a second.
  205.     You can set the number of frames to wait.
  206.  
  207.  
  208.  
  209. Statement : End
  210.  
  211.     End simply tells Blitz to clean up everything and the quit.
  212.  
  213.  
  214.  
  215.  
  216. S A V E  S C R E E N  E X A M P L E 
  217.  
  218. Our second Example is more interesting and more powerful, the program saves
  219. the workbench screen as a ILBM file so you can load it into a paint package
  220. like DPAINT. When you run the program it simply asks you for a save name and
  221. that is all, it then saves the Workbench screen to its destination file. 
  222. If you do not give a name or just press cancel then the program will just
  223. quit.
  224.  
  225.  
  226. Here follows the program :
  227.  
  228.  
  229.  
  230. ;
  231. ; Save screen - By Rudy van Etten..
  232. ;
  233.  
  234. WBStartup                   ; For startup from workbench
  235.  
  236. NoCli                       ; Don't run from default cli
  237.  
  238. WbToScreen 0                    ; Use the wbscreen as your own
  239.  
  240. WBenchToFront_                  ; Move it in front
  241.  
  242. MaxLen path$=192                ; Maximum characters in path$ is 192 
  243. MaxLen f$=192                   ; Same for f$
  244.  
  245. path$="Ram:"                    ; path$ is default "ram:"
  246.  
  247. ; ** Request the filename....
  248.  
  249. naam$=ASLFileRequest$("Save iff name..",path$,f$,"",50,30,100,180)
  250.  
  251. If naam$                            ; If naam$ is filled
  252.  
  253.   SaveScreen 0,naam$ : VWait 20 : End       ; Save it, wait , then end
  254.  
  255. Else                                ; If no name is given
  256.  
  257.   Beepscreen_ 0 : End                   ; Beep the screen, then end
  258.  
  259. End If                      
  260.      
  261.  
  262.  
  263.  
  264. After you typed it try it out. If you typed it correctly then it should
  265. compile Ok, else check for typing errors.
  266. If you have runned the program then there should be a ILBM file at your
  267. selected destination. Try to load it into a art package with the screen size
  268. 640,256. or 640,200 for American users.
  269.  
  270. Below is the explanation of some of the used commands.
  271.  
  272.  
  273.  
  274. Statement : NoCli
  275.  
  276.     NoCli is used to run you program without opening a standard cli
  277.     window. This command has no effect in the standalone compiled version
  278.     of your code.
  279.  
  280.  
  281.  
  282. Statement : WBenchToFront_
  283.  
  284.     WBenchToFront_ will move the workbench to the front of your display.
  285.  
  286.  
  287.  
  288. Statement : MaxLen StringVar=Expression
  289.  
  290.     MaxLen is used to define a block of memory for a string variable to
  291.     grow in.
  292.  
  293.  
  294.  
  295. Statement : ASLFileRequest$(Title$,Pathname$,Filename$[,Pattern][,x,y,w,h])
  296.  
  297.     he ASLFileRequest is build in as a standard in Kickstart 3.0, so no
  298.     need to use the less capable Blitz requester.
  299.  
  300.    Title$    is the text on the requester.
  301.    Pathname$    is which device or directory shall be given as a                 default.
  302.    Filename$     is which file to choose as a default.
  303.    Pattern     is used to view or hide files.
  304.    x           is the x coordinate of the upper-left side of the                 requester.
  305.    y           is the y coordinate of the upper side of the                     requester.
  306.    w           is the width of the requester.
  307.    y           is the height of the requester.
  308.  
  309.  
  310.  
  311. Statement : SaveScreen Screen#,Filename$
  312.  
  313.     SaveScreen is used to save the selected screen as a ILBM file, to be
  314.     later loaded in to a Paint Package.
  315.     Screen# is the screen to be saved, and Filename$ is how shall the
  316.     file be saved as.
  317.  
  318.  
  319.  
  320. Well this was our second little program and I hope you have learned something
  321. of it.
  322.  
  323. Now for some usefull hints tips and tricks when using blitz basic.
  324.  
  325.  
  326.  
  327. B L I T Z  H I N T S  A N D  T I P S . . . . 
  328.  
  329.  
  330. - If you wish to print on a bitmap in blitz mode the you must first use
  331.   BitmapOutput Bitmap# or else your program will halt.
  332.  
  333. - If you wish to read from the keyboard in blitzmode then first activate
  334.   key reading with BlitzKeys On.
  335.  
  336. - Use Cls [colour#] to clear you screen in Blitz or Amiga mode.
  337.  
  338. - Use cursor to change the size of your cursor (Cursor 1 = underlined
  339.   cursor, Cursor 0 = Default (full cursor)).
  340.  
  341. - Use Activate in Amiga mode to activate a window (Activate Window#).
  342.  
  343. - Use BlitzRepeat to change the key speed in Blitz Mode (BlitzRepeat Delay,
  344.   Speed)
  345.  
  346. - Use RawStatus to determine if a key is pressed -1 is given if the key is
  347.   pressed (RawStatus (32)).
  348.  
  349. - Use `Call` to jump to a adress (Call $40000)
  350.  
  351. - Use IncBin to include a Binary file in your program.
  352.  
  353. - Use AbsMouse to locate you MousePointer somewhere on the screen (only
  354.   available in Amiga mode).
  355.  
  356. - Use RelMouse to move your MousePointer (Amiga Mode only)
  357.  
  358. - Use MouseButton to simulate a mousebutton pressing (MouseButton 0,On).
  359.  
  360. - Use ClickButton to simulate a single mousebutton click. (ClickButton 0)
  361.  
  362. - Use Type String$ to simulate a typewriter typer.
  363.  
  364. - On AGA machines use AGARGB palette#,R,G,B to change the palette.
  365.   (AGARGB 1,255,10,255).
  366.  
  367. - How to open a hires screen in AGA, Screen 0,0,0,1280,256,8,$8020,"My
  368.   Screen",1,0.
  369.  
  370. - Use Poke.w $Dff180,a to change the background colour. (a=2)
  371.  
  372.  
  373. If you have any comments, questions, tips, example programs, or anything else
  374. that can be of interest to us or the readers then why not let me know.
  375.  
  376. You can contact me at the address below
  377.  
  378. Nicolaas Peckstraat 40
  379. 4651 DH Steenbergen NB
  380. Holland.
  381.